<template>
  <!-- 核销管理-核销案件池 --> 
  <section class="page case-verify-pool">
    <data-form :model="searchModel" :page="pageService" @onSearch="refreshData" @handleResetForm="handleResetForm">
      <template slot="inputs">
        <el-form-item label="借据号" prop="caseNumber">
          <el-input v-model="searchModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="批次号" prop="caseNumber">
          <el-input v-model="searchModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="客户编号" prop="personalName">
          <el-input v-model="searchModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="客户名称" prop="personalName">
          <el-input v-model="searchModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="流转来源" prop="verifyStatus">
          <el-select v-model="searchModel.verifyStatus" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('VerifyStatus')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="附件是否已提交" prop="verifyStatus">
          <el-select v-model="searchModel.verifyStatus" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('VerifyStatus')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="案件金额" prop="overdueAmount">
          <number-range v-model="searchModel.overdueAmount" :isInteger="true"></number-range>
        </el-form-item>
        <el-form-item label="逾期阶段" prop="overduePeriod">
          <el-select v-model="searchModel.overduePeriod" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('OverduePeriodStatus')" :key="index" :label="name" :value="code.replace(/M|\+/, '')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="逾期天数" prop="overdueDays">
          <number-range v-model="searchModel.overdueDays" :isInteger="true"></number-range>
        </el-form-item>
        <el-form-item label="系统来源" prop="sysCode">
          <el-select v-model="searchModel.sysCode" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('SysCode')" :key="index" :label="name" :value="code.replace(/M|\+/, '')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="searchModel.productName"></el-input>
        </el-form-item>
        <el-form-item label="地区" prop="area">
          <el-cascader v-model="searchModel.area" :options="$city.getCityData()" change-on-select clearable></el-cascader>
        </el-form-item>
        <el-form-item label="案件流入时间" prop="followInTime">
          <el-date-picker type="daterange" :editable="false" v-model="searchModel.followInTime" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
      </template>
    </data-form>
    <data-box :data="dataSet" :page="pageService"  @onPageChange="refreshData" :selectionList.sync="selectionList">
      <template slot="buttons">
        <el-button @click="downloadVerifiedCase" v-auth = "1904">导出核销案件</el-button>
      </template>
      <template slot="columns">
        <el-table-column prop="caseNumber" label="批次号" :min-width="$helper.getColumnWidth(6)">
        </el-table-column>
        <el-table-column prop="caseNumber" label="借据号" :min-width="$helper.getColumnWidth(6)">
        </el-table-column>
        <el-table-column prop="personalName" label="客户名称" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="mobileNo" label="手机号" :formatter="(row)=>$filter.encryptPhone(row.mobileNo)" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="idCard" label="证件号码" :formatter="(row)=>$filter.encryptIDCardFour(row.idCard)" :min-width="$helper.getColumnWidth(6)">
        </el-table-column>
        <el-table-column prop="area" label="地区" :min-width="$helper.getColumnWidth(4)" :formatter="(row) => $city.getInheritNames(Number(row.area))">
        </el-table-column>
        <el-table-column prop="overdueAmount" label="案件金额(元)" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="overduePeriod" label="逾期阶段" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="overdueDays" label="逾期天数" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="sysCode" label="系统来源" :formatter="(row) => $filter.encryptSysCode(row.sysCode)" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="productName" label="产品名称" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="perDueDate" label="还款日" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="commonFlag" label="附件是否提交" :min-width="$helper.getColumnWidth(4)" :formatter="(row) => $filter.dictConvert(row.commonFlag,'CommonFlag')">
        </el-table-column>
        <el-table-column prop="verifyStatus" label="核销状态" :min-width="$helper.getColumnWidth(4)" :formatter="(row) => $filter.dictConvert(row.verifyStatus,'VerifyStatus')">
        </el-table-column>
        <el-table-column prop="followInTime" label="案件流入时间" :formatter="(row) => $filter.dateTimeFormat(row.followInTime)" :min-width="$helper.getColumnWidth(5)">
        </el-table-column>
      </template>
    </data-box>

    <!--重新提交-->
    <el-dialog title="上传附件" width="900px" :visible.sync="dialog.isOpenVerifyFileUpload" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
      <verify-file-upload  ref="verify-file-upload" :rowData="rowData" @close="dialog.isOpenVerifyFileUpload = false" @refreshData="refreshData"></verify-file-upload>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Auth, Layout, Dependencies } from "~/core/decorator";
import { PageService } from "~/utils/page.service";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import NumberRange from "~/components/common/number-range.vue";
import { CaseVerifyService } from "~/services/domain-service/case-verify.service";
import { FileUploadService } from "~/services/file-service/file-upload.service.ts";
import { Getter } from 'vuex-class';
import VerifyFileUpload from '~/components/case-verify-manage/verify-file-upload.vue';
import { ApplyType, CASE_CHANNEL } from '~/config/enum.config';

@Layout("workspace")
@Component({
  components: {
    DataForm,
    DataBox,
    NumberRange,
    VerifyFileUpload,
  }
})
export default class CaseVerifyPool extends Vue {
  @Dependencies(PageService)
  private pageService: PageService;
  @Dependencies(CaseVerifyService)
  private caseVerifyService: CaseVerifyService;
  @Dependencies(FileUploadService)
  private fileUploadService: FileUploadService;
  // 数据
  private dataSet: any[] = []
  private applyType = ApplyType.turn
  private fromChannel: string = CASE_CHANNEL.verify
  private selectionList: any = []
  private rowData: any = null
  private searchModel: any = {
    caseNumber: "",
    personalName: "",
    mobileNo: "",
    idCard: "",
    customerCategory: "",
    sysCode: "",
    productName: "",
    overdueAmount: {
      max: "",
      min: ""
    },
    overduePeriod: "",
    overdueDays: {
      max: "",
      min: ""
    },
    followInTime: "",
    area: [],
    turnSource: "",
    commonFlag: "",
    verifyStatus: "",
  };
  // 弹框控制
  private dialog: any = {
    isOpenCaseConfirmation: false,
    isOpenApply: false,
    isOpenVerifyFileUpload: false,
  };

  private mounted() {
    this.refreshData()
  }
  private refreshData() {
    this.caseVerifyService.getAllVerifyInfos(this.searchModel, this.pageService).subscribe(
      data => {
        this.dataSet = data
        if(this.dataSet){
          this.dataSet.forEach(x=>{
            x.overduePeriod>12?x.overduePeriod = 'M12+':x.overduePeriod = 'M'+x.overduePeriod
          })
        }
      }
    )
  }
  


  /**
   * 导出核销案件
   */
  private viewClick(rowData) {
    this.fileUploadService.getAllUploadFileByIds(rowData.fileIds).subscribe(
      data => {
        const fileList = data.map(v => {
          return {
            url: v.url,
            filename: v.fileName
          }
        })
        this.$common.downloadAll(fileList)
      }
    )
  }

  private get selectedCaseIds() {
    return this.selectionList.map((v) => v.id);
  }

  /**
   * 需要手动重置的表单项
   */
  private handleResetForm() {
    this.searchModel.overdueAmount = { max: "", min: "" }
    this.searchModel.overdueDays = { max: "", min: ""}
  }

  /**
   * 下载案件
   */
  private downloadVerifiedCase(){
    if(this.dataSet.length === 0){
      this.$message("暂无数据可以导出")
      return
    }
    const ids =this.selectionList? this.selectionList.map((v) => v.id):'';
    const request: any = {
      ...this.searchModel,
      caseIds: ids,
    }
    this.caseVerifyService.exportVerifyInfos(request).subscribe(
      data=>{
        this.$common.downloadFile(data.url,'核销案件.xls')
      }
    )
  }
}
</script>

<style lang="less">
</style>
